<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>批量下载</title>
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<form id="form"  action="/spider/download" method="post" enctype="multipart/form-data">
    <table>
        <tr><td>文件名:<input type="text" name="name" id="name"></td></tr>
        <tr><td>地址:<textarea name="urls" style="width:900px;height:500px" id="textarea"></textarea></td></tr>
        <tr><td>批量上传文件:<input type="file" id="file" name="file"></td></tr>
        <tr><td>总计:<span id="num">0</span>行</td></tr>
        <tr><td><input type="checkbox" value="true" name="onlyOne" id="onlyOne" checked>是否只下载第一张</td></tr>
        <tr><td><input type="button" value="提交" id = "sub" onclick="commit()"></td></tr>
    </table>
</form>
<script>
    document.getElementById("textarea").addEventListener("input",test)
    function test() {
        var str = document.getElementById('textarea').value.split("\n");
        document.getElementById('num').innerHTML = "" + str.length;
    }

    function commit(){
        if($("#name").val()==null||$("#name").val() == undefined||$("#name").val()==""){
            alert("请输入文件名!")
            return;
        }
        if($("#name").val().indexOf(".zip")==-1||$("#name").val().indexOf(".zip")!=$("#name").val().length-"zip".length){
            $("#name").val($("#name").val()+".zip");
        }
        document.getElementById("sub").disabled='true';
        $.ajax({
            url:"/spider/downloadComplate",
            type:"post",
            success:function(){
                document.getElementById("sub").disabled=false;
            }
        })
        document.getElementById("form").submit();
    }
</script>
</body>
</html>